package com.example.myapp;

import io.rong.imkit.RongIM;
import io.rong.imlib.RongIMClient.ConnectCallback;
import io.rong.imlib.RongIMClient.ErrorCode;
import io.rong.imlib.model.Conversation;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

	private String token = "7EdKPEpxF4MkKJqo9ZeLbiawPJc1LoArkcxCJHV8DXWyNm10mXEzWbzB1gr2YWwIhFRta5zF7xViCs/lRb112w==";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		// 连接融云服务器
		this.findViewById(android.R.id.text1).setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				RongIM.connect(token, new ConnectCallback() {

					@Override
					public void onError(ErrorCode arg0) {
						Toast.makeText(MainActivity.this, "connect onError", Toast.LENGTH_SHORT).show();
					}

					@Override
					public void onSuccess(String arg0) {
						Toast.makeText(MainActivity.this, "connect onSuccess", Toast.LENGTH_SHORT).show();
					}
				});

			}
		});

		// 启动会话列表
		this.findViewById(android.R.id.button1).setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				RongIM.getInstance().startConversationList(MainActivity.this);
			}
		});

		// 启动会话列表
		this.findViewById(android.R.id.button2).setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				RongIM.getInstance().startConversation(MainActivity.this, Conversation.ConversationType.PRIVATE, "9527", "聊天标题");
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
